package com.jsgt.greekfire.ui.mine.user.messagelist

import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import com.fhx.core.base.BaseActivity
import com.jsgt.greekfire.R
import com.jsgt.greekfire.ui.mine.user.messagelist.adapter.MessageAdapter
import com.jsgt.greekfire.factory.UserViewModelFactory
import com.jsgt.greekfire.ui.mine.user.messagelist.message.MessageActivity
import com.jsgt.greekfire.viewmodel.UserViewModel
import kotlinx.android.synthetic.main.activity_message_list.*

/**
 * 通知列表
 * author fhx
 * create time 2020/4/22 20:20
 **/
class MessageListActivity : BaseActivity() {
    private val userViewModel: UserViewModel by lazy {
        ViewModelProvider(
            this,
            UserViewModelFactory()
        ).get(UserViewModel::class.java)
    }
    private var page: Int = 1
    private val limit: Int = 20

    override fun getLayoutId(): Int = R.layout.activity_message_list

    override fun needFitsSystemWindows(): Boolean {
        return false
    }

    override fun main() {
        setStatusBar(R.color.transparent, false, R.color.white)
        title = getString(R.string.msg_center)
        val messageAdapter =
            MessageAdapter()
        msg_rv.adapter = messageAdapter
        messageAdapter.itemClickListner = {
            MessageActivity.start(
                mContext!!,
                it
            )
        }
        showProgress(true)
        userViewModel.noticeList(page, limit)
        userViewModel.noticeListLiveData.observe(this, Observer {
            showProgress(false)
            messageAdapter.addData(it)
        })
        userViewModel.errorLiveData.observe(this, Observer {
            showProgress(false)
        })
    }
}